
//
//  UIImage + Extension.swift
//  DDPictureSelectorTest
//
//  Created by dqw on 15/8/8.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

extension UIImage {
    
    func scaledImage(width: CGFloat) -> UIImage {
        
        if size.width < width {
            return self
        }
        let scale = size.height / size.width
        let height = width * scale
        let s = CGSize(width: width, height: height)
        UIGraphicsBeginImageContext(s)
        drawInRect(CGRect(origin: CGPointZero, size: s))
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return newImage
    }
}
